package com.bdc.whatwhat.utils;

import android.util.Log;

/**
 * Created by gfimac on 23/07/2014.
 */
public class NumberUtils {

    public static String format(String nombre){
        long nb = Long.parseLong(nombre);
        String nbString = "";

        try {

            if (nb < 1000)
                nbString = "" + nb;
            else if (nb < 1000000) {  // 125'668
                long milliers = nb / 1000;
                long reste = nb - milliers * 1000;

                nbString = milliers + "'" + reste;
            } else if (nb < 1000000000) { // 125 m 668
                long millions = nb / 1000000;
                long milliers = (nb - millions * 1000000) / 1000;

                nbString = millions + " m " + milliers;
            } else { // 125 m 668
                long milliards = nb / 1000000000;

                nbString = milliards + " M ";
            }
        }catch (Exception e){
            nbString = nombre;
            e.printStackTrace();
        }

        return nbString;
    }

    public static void tester(){
        Log.d("NumberUtils", format("125668")); // 125'668
        Log.d("NumberUtils", format("125668000")); // 125 m 668
        Log.d("NumberUtils", format("125668000000")); // 125 m 668
    }

}
